#include <iostream>

using std::cout;
using std::endl;


template <typename T>
struct type_traits {
    template<class C> //匹配C::value_type为类型成员
    static typename C::value_type get_type(typename C::value_type *);

    template <class C> //匹配其他情况
    static void get_type(...);

    typedef decltype(get_type<T>(0)) value_type;
};

template <typename T> 
struct type_traits<T*> {
     typedef T value_type;
};

template<typename T>
struct type_traits<const T*> {
    typedef T value_type;
};

template <class T>
struct MyIter {
    typedef T value_type; // 内嵌型别声明
    T* ptr;
    MyIter(T* p = 0) : ptr(p) {}
    T& operator*() const { return *ptr; }
};

int main() {
    cout << "sizeof(void): " << sizeof(type_traits<void>::value_type) << endl;
    cout << "sizeof(int): " << sizeof(type_traits<int*>::value_type) << endl;
    cout << "sizeof(const int): " << sizeof(type_traits<const int*>::value_type) << endl;
    cout << "sizeof(double): " << sizeof(type_traits< MyIter<double> >::value_type) << endl;
    return 0;
}
